import { LayerManager } from "../../manager/LayerManager";
import { Global } from "../../../../com/gengine/global/Global";
import { MaskInfo } from "./MaskInfo";
type int = number;
//class UIMaskEffect
    
    export  class UIMaskEffect /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._layer = LayerManager.guideLayer;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._clickBack != null) 
            {
                this._clickBack();
            }
            return;
        }

        /* internal  */drawMask(): void
        {
            var loc1=null;
            graphics.clear();
            graphics.lineStyle(0, 0, 0);
            graphics.beginFill(0, this._maskAlpha);
            graphics.drawRect(0, 0, Global.stage.stageWidth, Global.stage.stageHeight);
            if (this._masks) 
            {
                var loc2=0;
                var loc3=this._masks;
                label239: for(loc1 of loc3) 
                {
                    var loc4=loc1.shape;
                    switch (loc4) 
                    {
                        case MaskInfo.Shape_Cycle:
                        {
                            graphics.drawCircle(loc1.x, loc1.y, loc1.width);
                            continue label239;
                        }
                        case MaskInfo.Shape_Rect:
                        {
                            graphics.drawRect(loc1.x, loc1.y, loc1.width, loc1.height);
                            continue label239;
                        }
                    }
                }
            }
            graphics.endFill();
            return;
        }

        /* internal  */onTimeOutHandler(): void
        {
            this.hideMask();
            return;
        }

        public showMask(arg1: Array<any>, arg2: int=10000, arg3: number=0.3, arg4: Function=null): void
        {
            this.hideMask();
            this._clickBack = arg4;
            this._masks = arg1;
            this._maskAlpha = arg3;
            this.drawMask();
            this._layer.addChild(this);
            if (arg2 > 0) 
            {
                this._timeKey = flash.utils.setTimeout(this.onTimeOutHandler, arg2);
            }
            return;
        }

        public hideMask(): void
        {
            this._clickBack = null;
            flash.utils.clearTimeout(this._timeKey);
            graphics.clear();
            if (this._masks) 
            {
                this._masks.length = 0;
            }
            if (this._layer.contains(this)) 
            {
                this._layer.removeChild(this);
            }
            return;
        }

        public get isHide(): Boolean
        {
            return this.parent == null;
        }

        public stageResize(): void
        {
            if (this.parent) 
            {
                this.drawMask();
            }
            return;
        }

        /* internal */ /* var */_masks: Array<any>;

        /* internal */ /* var */_layer: Object /* flash.display.DisplayObjectContainer */;

        /* internal */ /* var */_timeKey: uint;

        /* internal */ /* var */_maskAlpha: number=0.3;

        /* internal */ /* var */_clickBack: Function;
    }
